import { Token } from '@/types/data'
import { LoginAction } from '@/types/store'
import { getToken } from '@/utils/storage'

const initValue: Token = getToken()
export default function login(state = initValue, action: LoginAction): Token {
  if (action.type === 'login/login') {
    return action.payload
  }
  if (action.type === 'login/logout') {
    return { token: '', refresh_token: '' }
  }
  return state
}
